<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<title>debug.h File Reference</title>
<link href="doxygen_tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="doxygen_content.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="top">
 <div id="titlearea">
  <table height="72px" width="100%" cellspacing="0" cellpadding="0">
   <tbody>
    <tr>
     <td width="10%">&nbsp;</td>
     <td><a href="https://github.com/Genivia/RE-flex"><img src="reflex-logo.png"/></a></td>
     <td>
      <div style="float: right; font-size: 18px; font-weight: bold;">debug.h File Reference</div>
      <br>
      <div style="float: right; font-size: 10px;">updated Fri Nov 22 2019 by Robert van Engelen</div>
     </td>
     <td width="10%">&nbsp;</td>
    </tr>
   </tbody>
  </table>
 </div>
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_bb8a7beb94a1b7afd52842cbf47ddd3e.html">reflex</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a>  </div>
  <div class="headertitle">
<div class="title">debug.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>RE/flex debug logs and assertions.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for debug.h:</div>
<div class="dyncontent">
<div class="center"><img src="debug_8h__incl.png" border="0" usemap="#debug_8h" alt=""/></div>
</div>
</div><div class="textblock"><div class="dynheader">
This graph shows which files directly or indirectly include this file:</div>
<div class="dyncontent">
<div class="center"><img src="debug_8h__dep__incl.png" border="0" usemap="#debug_8hdep" alt=""/></div>
<map name="debug_8hdep" id="debug_8hdep">
<area shape="rect" id="node2" href="absmatcher_8h.html" title="RE/flex abstract matcher base class and pattern matcher class. " alt="" coords="249,80,352,107"/>
<area shape="rect" id="node8" href="pattern_8h.html" title="RE/flex regular expression pattern compiler. " alt="" coords="378,80,453,107"/>
<area shape="rect" id="node3" href="abslexer_8h.html" title="RE/flex abstract lexer base class for reflex&#45;generated scanners. " alt="" coords="5,155,89,181"/>
<area shape="rect" id="node5" href="boostmatcher_8h.html" title="Boost::regex&#45;based matcher engines for pattern matching. " alt="" coords="113,155,227,181"/>
<area shape="rect" id="node6" href="matcher_8h.html" title="RE/flex matcher engine. " alt="" coords="375,155,456,181"/>
<area shape="rect" id="node7" href="stdmatcher_8h.html" title="C++11 std::regex&#45;based matcher engines for pattern matching. " alt="" coords="251,155,350,181"/>
<area shape="rect" id="node4" href="flexlexer_8h.html" title="RE/flex Flex&#45;compatible FlexLexer base class and Lex/Flex&#45;compatible macros. " alt="" coords="6,229,89,256"/>
<area shape="rect" id="node9" href="reflex_8h.html" title="RE/flex scanner generator replacement for Flex/Lex. " alt="" coords="480,155,545,181"/>
<area shape="rect" id="node10" href="reflex_8cpp.html" title="RE/flex scanner generator replacement for Flex/Lex. " alt="" coords="473,229,553,256"/>
</map>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:aad4e5b6078e35a063d909d9a2db2e5e0"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="debug_8h.html#aad4e5b6078e35a063d909d9a2db2e5e0">ASSERT</a>(c)</td></tr>
<tr class="memdesc:aad4e5b6078e35a063d909d9a2db2e5e0"><td class="mdescLeft">&#160;</td><td class="mdescRight">If ASSERT not defined, make ASSERT a no-op.  <a href="#aad4e5b6078e35a063d909d9a2db2e5e0">More...</a><br /></td></tr>
<tr class="separator:aad4e5b6078e35a063d909d9a2db2e5e0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1d20ed9010534224290496a3ec91b1fc"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="debug_8h.html#a1d20ed9010534224290496a3ec91b1fc">DBGCHK</a>(c)&#160;&#160;&#160;(void)0</td></tr>
<tr class="separator:a1d20ed9010534224290496a3ec91b1fc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a53b7d4ef6b5cc76b0bce2fd6fe5733ed"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="debug_8h.html#a53b7d4ef6b5cc76b0bce2fd6fe5733ed">DBGLOG</a>(...)&#160;&#160;&#160;(void)0</td></tr>
<tr class="memdesc:a53b7d4ef6b5cc76b0bce2fd6fe5733ed"><td class="mdescLeft">&#160;</td><td class="mdescRight">When compiled with -DDEBUG, adds a timestamped log entry with a printf-formatted message.  <a href="#a53b7d4ef6b5cc76b0bce2fd6fe5733ed">More...</a><br /></td></tr>
<tr class="separator:a53b7d4ef6b5cc76b0bce2fd6fe5733ed"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a42d3120c8e5ce7a7d0edc67db476de11"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="debug_8h.html#a42d3120c8e5ce7a7d0edc67db476de11">DBGLOGN</a>(...)&#160;&#160;&#160;(void)0</td></tr>
<tr class="memdesc:a42d3120c8e5ce7a7d0edc67db476de11"><td class="mdescLeft">&#160;</td><td class="mdescRight">When compiled with -DDEBUG, adds a log entry with a printf-formatted message.  <a href="#a42d3120c8e5ce7a7d0edc67db476de11">More...</a><br /></td></tr>
<tr class="separator:a42d3120c8e5ce7a7d0edc67db476de11"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8f77c970ada64b34cd82308462c9ea76"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="debug_8h.html#a8f77c970ada64b34cd82308462c9ea76">DBGLOGA</a>(...)&#160;&#160;&#160;(void)0</td></tr>
<tr class="memdesc:a8f77c970ada64b34cd82308462c9ea76"><td class="mdescLeft">&#160;</td><td class="mdescRight">When compiled with -DDEBUG, appends a printf-formatted message to the last log entry.  <a href="#a8f77c970ada64b34cd82308462c9ea76">More...</a><br /></td></tr>
<tr class="separator:a8f77c970ada64b34cd82308462c9ea76"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>RE/flex debug logs and assertions. </p>
<dl class="section author"><dt>Author</dt><dd>Robert van Engelen - <a href="#" onclick="location.href='mai'+'lto:'+'eng'+'el'+'en@'+'ge'+'niv'+'ia'+'.co'+'m'; return false;">engel<span style="display: none;">.nosp@m.</span>en@g<span style="display: none;">.nosp@m.</span>enivi<span style="display: none;">.nosp@m.</span>a.co<span style="display: none;">.nosp@m.</span>m</a> </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>(c) 2015-2017, Robert van Engelen, Genivia Inc. All rights reserved. </dd>
<dd>
(c) BSD-3 License - see LICENSE.txt</dd></dl>
<p>Exploiting macro magic to simplify debug logging.</p>
<h2>Usage </h2>
<p><code>DBGLOG(format, ...)</code> creates a timestamped log entry with a printf-formatted message. The log entry is added to a log file or sent to <code>stderr</code> as specified:</p>
<table class="doxtable">
<tr>
<th>Source files compiled with </th><th>DBGLOG(...) entry added to  </th></tr>
<tr>
<td><code>c++ -DDEBUG</code> </td><td><code>DEBUG.log</code> </td></tr>
<tr>
<td><code>c++ -DDEBUG=TEST</code> </td><td><code>TEST.log</code> </td></tr>
<tr>
<td><code>c++ -DDEBUG=</code> </td><td><code>stderr</code> </td></tr>
</table>
<p><code>DBGLOGN(format, ...)</code> creates a log entry without a timestamp.</p>
<p><code>DBGLOGA(format, ...)</code> appends the formatted string to the previous log entry.</p>
<p><code><a class="el" href="debug_8h.html#a1d20ed9010534224290496a3ec91b1fc">DBGCHK(condition)</a></code> calls <code>assert(condition)</code> when compiled in DEBUG mode.</p>
<p>The utility macro <code>DBGSTR(const char *s)</code> returns string <code>s</code> or <code>"(null)"</code> when <code>s == NULL</code>.</p>
<h2>Example </h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">reflex/debug.h</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> <a class="code" href="reflex_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">  FILE *fd;</div><div class="line">  <a class="code" href="debug_8h.html#a53b7d4ef6b5cc76b0bce2fd6fe5733ed">DBGLOG</a>(<span class="stringliteral">&quot;Program start&quot;</span>);</div><div class="line">  <span class="keywordflow">if</span> ((fd = fopen(<span class="stringliteral">&quot;foo.bar&quot;</span>, <span class="stringliteral">&quot;r&quot;</span>)) == NULL)</div><div class="line">  {</div><div class="line">    <a class="code" href="debug_8h.html#a53b7d4ef6b5cc76b0bce2fd6fe5733ed">DBGLOG</a>(<span class="stringliteral">&quot;Error %d: %s &quot;</span>, errno, DBGSTR(strerror(errno)));</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; argc; ++i)</div><div class="line">      <a class="code" href="debug_8h.html#a8f77c970ada64b34cd82308462c9ea76">DBGLOGA</a>(<span class="stringliteral">&quot; %s&quot;</span>, argv[1]);</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">  {</div><div class="line">    <a class="code" href="debug_8h.html#a1d20ed9010534224290496a3ec91b1fc">DBGCHK</a>(fd != NULL);</div><div class="line">    <span class="comment">// OK, so go ahead to read foo.bar ...</span></div><div class="line">    <span class="comment">// ...</span></div><div class="line">    fclose(fd);</div><div class="line">  }</div><div class="line">  <a class="code" href="debug_8h.html#a53b7d4ef6b5cc76b0bce2fd6fe5733ed">DBGLOG</a>(<span class="stringliteral">&quot;Program end&quot;</span>);</div><div class="line">}</div></div><!-- fragment --><p>Compiled with <code>-DDEBUG</code> this example logs the following messages in <code>DEBUG.log</code>:</p>
<div class="fragment"><div class="line">140201/225654.692194   example.cpp:11   Program has started</div><div class="line">140201/225654.692564   example.cpp:15   Error 2: No such file or directory</div><div class="line">140201/225654.692577   example.cpp:17   Program ended</div></div><!-- fragment --><p>The first column records the date (140201 is February 1, 2014) and the time (225654 is 10:56PM + 54 seconds) with microsecond fraction. The second column records the source code file name and the line number of the <code>DBGLOG</code> command. The third column shows the printf-formatted message.</p>
<p>The <code>DEBUG.log</code> file is created in the current directory when it does not already exist.</p>
<p>Techniques used:</p>
<ul>
<li>Variadic macros with <code>__VA_ARGS__</code>.</li>
<li>Standard predefined macros <code>__FILE__</code> and <code>__LINE__</code>.</li>
<li>Macro "stringification": expand content of macro <code>DEBUG</code> as a string in a macro body.</li>
<li><code>#if DEBUG + 0</code> to test whether macro <code>DEBUG</code> is set to a value, since <code>DEBUG</code> is 1 when set without a value (for example at the command line).</li>
<li><code>"" __VA_ARGS__</code> forces <code>__VA_ARGS__</code> to start with a literal format string (printf security advisory). </li>
</ul>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a class="anchor" id="aad4e5b6078e35a063d909d9a2db2e5e0"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define ASSERT</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">c</td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>If ASSERT not defined, make ASSERT a no-op. </p>

</div>
</div>
<a class="anchor" id="a1d20ed9010534224290496a3ec91b1fc"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DBGCHK</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">c</td><td>)</td>
          <td>&#160;&#160;&#160;(void)0</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a class="anchor" id="a53b7d4ef6b5cc76b0bce2fd6fe5733ed"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DBGLOG</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>...</em></td><td>)</td>
          <td>&#160;&#160;&#160;(void)0</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>When compiled with -DDEBUG, adds a timestamped log entry with a printf-formatted message. </p>

</div>
</div>
<a class="anchor" id="a8f77c970ada64b34cd82308462c9ea76"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DBGLOGA</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>...</em></td><td>)</td>
          <td>&#160;&#160;&#160;(void)0</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>When compiled with -DDEBUG, appends a printf-formatted message to the last log entry. </p>

</div>
</div>
<a class="anchor" id="a42d3120c8e5ce7a7d0edc67db476de11"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DBGLOGN</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>...</em></td><td>)</td>
          <td>&#160;&#160;&#160;(void)0</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>When compiled with -DDEBUG, adds a log entry with a printf-formatted message. </p>

</div>
</div>
</div><!-- contents -->
<hr class="footer">
<address class="footer"><small>
Converted on Fri Nov 22 2019 14:30:50 by <a target="_blank" href="http://www.doxygen.org/index.html">Doxygen</a> 1.8.11</small></address>
<br>
<div style="height: 246px; background: #DBDBDB;">
</body>
</html>
